package edu.gatech.cs4400.spring2014.A8.model;

import java.sql.SQLException;


/**
 * Class extended by any queries seeking to write data to the database.
 * Handles the connction and execution of the query using the data 
 * contained in the protected String variable sql.
 * 
 * @author Stephen
 *
 */
public abstract class WriteQuery extends Query {
	protected Exception exception;

	/**
	 * Attempt to write the data to the database.
	 * An SQL exception is assumed to indicate a failure of the insertion.
	 */
	protected boolean execute() {
		boolean result = false;
		if (!executed) {
			try {
				ConnectionManager.statement.execute(sql);
				result = true;
			}
			catch (SQLException e) {
				failed = true;
				exception = e;
			}
			executed = true;
		}
		return result;
	}
	
	protected void reset() {
		executed = false;
		failed = false;
	}
}
